package com.nhjf.dao.payMessage;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.payMessage.PayMessage;
import com.nhjf.pojo.qo.payMessage.PayMessageQo;
@Repository
public class PayMessageDao extends BaseDao<PayMessage, PayMessageQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, PayMessageQo qo) {
		// TODO Auto-generated method stub
		criteria.setFetchMode("coursesSeries", qo.isSeachCoursesSeries()?FetchMode.JOIN:FetchMode.SELECT);	
		criteria.setFetchMode("user", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
		if(qo.getCoursesSeries()!=null) {
			criteria.add(Restrictions.eq("coursesSeries.id",qo.getCoursesSeries()));
		}
		if(qo.getUser()!=null) {
			criteria.add(Restrictions.eq("user.id",qo.getUser()));
		}
		if(qo.getIsPaySuccess()!=null) {
			criteria.add(Restrictions.eq("isPaySuccess",qo.getIsPaySuccess()));
		}
		if(qo.getPayMessageId()!=null) {
			criteria.add(Restrictions.eq("id",qo.getPayMessageId()));
		}
		if(StringUtils.isNotBlank(qo.getMessage())) {
			criteria.add(Restrictions.eq("message",qo.getMessage()));
		}
		if(Double.isNaN(qo.getAmount())) {
			criteria.add(Restrictions.eq("amount",qo.getAmount()));
		}
		return criteria;
	}

	@Override
	protected Class<PayMessage> getEntityClass() {
		// TODO Auto-generated method stub
		return PayMessage.class;
	}

}
